//
//  SEGFangHaoListViewModel.m
//  SEGViewModel
//
//  Created by 山刘 on 2020/6/5.
//

#import "SEGFangHaoListViewModel.h"
@interface SEGFangHaoListViewModel()
@end

@implementation SEGFangHaoListViewModel
#pragma mark - Init
-(instancetype)init{
    if (self = [super init]) {
        [self racInit];
    }
    return self;
}
- (void)racInit {
    
    @weakify(self);
    
    _requestDataCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            
            @strongify(self);
            
            NSDictionary *params = @{@"houseUnit":[SEGUtils ValueToString:self.unitModel.unitId], //单元ID,没有单元传0或-1
                                     @"buildId":[SEGUtils ValueToString:self.buildModel.buildId] //楼栋ID
            };
            // 请求小区内所有房号列表
            [self.myProfileManager requestQueryHouseByParans:params Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [self.messageSubject sendNext:errorMessage];
                }
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }];
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
}

#pragma mark - Publish Methods

#pragma mark - Private Methods

#pragma mark - Getter
- (SEGUnitByBuildIdModel *)unitModel {
    if (!_unitModel) {
        _unitModel = [[SEGUnitByBuildIdModel alloc] init];
        _unitModel.unit = @"";
        _unitModel.unitId = @"0"; //单元ID,没有单元传0或-1
    }
    return _unitModel;
}
- (SEGMyProfileManager *)myProfileManager {
    if (!_myProfileManager) _myProfileManager = [[ SEGMyProfileManager alloc]init];
    return _myProfileManager;
}
-(RACSubject *)messageSubject{
    if (!_messageSubject) {
        _messageSubject = [RACSubject subject];
    }
    return _messageSubject;
}
#pragma mark - Stter
@end
